package com.lynn.common.net.interceptor

import com.lynn.common.utils.LoggerUtil
import com.orhanobut.logger.Logger
import okhttp3.Interceptor
import okhttp3.Response

/**
 * @description: 响应（返回）拦截器
 * @author: bailing
 * @datetime: 2025/5/27 14:30
 **/
class ResponseInterceptor : Interceptor {

    // Override the intercept method from the Interceptor interface
    override fun intercept(chain: Interceptor.Chain): Response {
        // Get the current time in milliseconds
        val requestTime = System.currentTimeMillis()
        // Proceed with the request and get the response
        val response = chain.proceed(chain.request())
        // Get the current time in milliseconds again
        val responseTime = System.currentTimeMillis()
        // Log the time taken for the request
        val msg = "requestSpendTime= %s ms".format(responseTime - requestTime)
        Logger.d(msg)
        // Return the response
        return response
    }
}